/*
 * OPIAM Suite
 *
 * Distributable under LGPL license.
 * See terms of license at gnu.org.
 */

package opiam.admin.applis.demo.actions;

import opiam.admin.faare.struts.actions.SecureAction;

import org.apache.log4j.Logger;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import java.io.IOException;


/**
 * This action only performs a forward to the "success" URI keeping the cart in the request.
 *
 * This Action class inherits from SecureAction class.
 * The SecureAction class checks that the user is connected before calling
 * the action methods.
 */
public class CartStraightForwardAction extends SecureAction
{
    /** Instance of the log4j logger.
     * Used to generate the execution traces. */
    private static Logger _logger =
        Logger.getLogger(CartStraightForwardAction.class.getName());

    /**
     * This method is called to execute the action once the checks have been
     * performed by the SecureAction class.
     *
     * @param mapping              Struts mapping data.
     * @param actionForm           FormBean associated with the action.
     * @param request              HTTP request.
     * @param httpServletResponse  HTTP response.
     *
     * @return An ActionForward.
     *
     * @throws IOException  An I/O exception if failed or interrupted I/O operations occurs.
     * @throws ServletException A ServletException if the servlet has a problem.
     */
    @Override
	public ActionForward secureExecute(ActionMapping mapping,
                                       ActionForm actionForm,
                                       HttpServletRequest request,
                                       HttpServletResponse httpServletResponse
                                      ) throws IOException, ServletException
    {
        // Gets the cartname
        String cartname = request.getParameter("cartname");

        if (cartname == null)
        {
            cartname = "panier1";
        }

        _logger.debug("cartname = " + cartname);

        // Returns the list 
        if (mapping.getPath().indexOf("Full") > 0)
        {
        	// for the frame 
        	request.getSession().setAttribute("cartname", cartname);
        }
        else
        {
        	request.setAttribute("cartname", cartname);
        }

        // return the "success" URI of the action as defined in the
        // struts-config.xml.
        return (mapping.findForward("success"));
    }
}
